package Nio;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.01.20.13.25
 */
public class Nio6 {
    public static void main(String[] args) throws IOException {
        //遍历目录
        //Files.createDirectories(Paths.get(""));
        //删除只能是空目录
        //Files.delete(Paths.get(""));
        Path path=Paths.get(System.getProperty(""));
        var dirs=Files.newDirectoryStream(path);
        for(Path p:dirs){
            System.out.println(p.getFileName()+":"+(Files.isDirectory(p)?"目录":"文件"));
        }
    }




    public static void deldir(Path path){
        try(var dirs=Files.newDirectoryStream(path)) {
         for(Path p:dirs){
             if(Files.isDirectory(p)){
                 deldir(p);
             }else {
                 Files.delete(p);
             }
             System.out.println(p.getFileName());
             System.out.println(Files.isDirectory(p));
         }

        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            Files.delete(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
